#include "sdf.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main()
{
    void **pdh;
    pdh = (void **)malloc(20);
    int ret;
    ret = SDF_OpenDevice(pdh);
    if (ret != SDR_OK)
    {
        printf("OpenDevice Failed!\n");
    }
    else
    {
        printf("OpenDevice Successed!\n");
    }

    DEVICEINFO a;
    ret = SDF_GetDeviceInfo(*pdh, &a);
    if (ret != SDR_OK)
    {
        printf("GetDeviceInfo Failed!\n");
    }
    else
    {
        printf("GetDeviceInfo Successed!\n");
        printf("DeviceName:%s\n", a.DeviceName);
        printf("DeviceVersion:%d\n", a.DeviceVersion);
    }

    // 签名和验签示例
    unsigned char data[] = "Hello, World!";
    unsigned int dataLength = strlen((char *)data);
    ECCSignature signature;
    unsigned char publicKey[ECCref_MAX_LEN * 2]; // 假设公钥长度为ECCref_MAX_LEN * 2
    unsigned char privateKey[ECCref_MAX_LEN]; // 假设私钥长度为ECCref_MAX_LEN

    // 签名
    ret = SDFInternalSign_ECC(*pdh, 0, data, dataLength, &signature);
    if (ret != SDR_OK)
    {
        printf("Sign Failed!\n");
    }
    else
    {
        printf("Sign Successed!\n");
    }

    // 验签
    ret = SDF_InternalVerify_ECC(*pdh, 0, data, dataLength, &signature);
    if (ret != SDR_OK)
    {
        printf("Verify Failed!\n");
    }
    else
    {
        printf("Verify Successed!\n");
    }

    ret = SDF_CloseDevice(*pdh);
    if (ret != SDR_OK)
    {
        printf("CloseDevice Failed!\n");
    }
    else
    {
        printf("CloseDevice Successed!\n");
    }

    free(pdh);
    return 0;
}
